#ifndef GLVERTEXBUFFER_H
#define GLVERTEXBUFFER_H

#include "VertexBuffer.h"
#include "GL/OpenGL.h"

NS_B2D_BEGIN

struct GLVertexAttribute
{
	static const GLenum dataTypes[];
};

///
/// OpenGL implementation of a vertex buffer
///
class GLVertexBuffer
	: public VertexBuffer
{
public:
	// Utility struct to bind an vertex buffer and release
	// it when the lock goes out of scope
	struct BindLock
	{
		BindLock(GLuint buffer) { glBindBuffer(GL_ARRAY_BUFFER, buffer); }
		~BindLock(void) { glBindBuffer(GL_ARRAY_BUFFER, 0); }
	};

private:
	GLuint mBufferName;

	char* mTempData;
	size_t mLockOffset;
	size_t mLockSize;
	bool mLockedForWritting;


public:
	GLVertexBuffer(void);
	virtual ~GLVertexBuffer(void);

	void* getHandle(void) const { return reinterpret_cast<void*>(mBufferName); }
	bool isInitialised(void) const { return mBufferName != 0; }

private:
	void resizeImpl(void);

	void lockImpl(LockMode mode, void** dst, size_t offset, size_t size);
	void unlockImpl(void);

	/// Create the index buffer
	void create(void);
	/// Destroy the index buffer
	void destroy(void);
};

NS_B2D_END

#endif